/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFPostMagTracker
  \brief trackers for tracking downstream the dipole magnet
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-11-02
  \date 2021-11-20 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-11-02   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFPostMagTracker_h
#define ETFPostMagTracker_h

#include "ETFTracker.h"

class ETFTOFWall;

class ETFPostMagTracker : public ETFTracker{
public:
  ETFPostMagTracker(const char *name = "");
  virtual ~ETFPostMagTracker();

  /// \param type: 0: X; 1: U; 2: V
  using ETFTracker::Map;
  virtual void Map(); ///< finding 2D tracks
  virtual void TrackMerge(); ///< merge 2D tracks to 3D ones
  virtual void Map3D(); ///< finding 2D tracks

  ETFTOFWall *GetTOFWall() const{ return fTOFWall; }
  double GetPhiAvrg() const{ return fPhiAvrg; }

  ClassDef(ETFPostMagTracker, 1);

protected:
  /// overloaded Compare overshadows all versions in the parent class
  /// this statement recovers this effect
  using ETFTracker::Compare;
  using ETFTracker::UpdateHitPos;
  virtual void UpdateHitPos(); ///< update the hit position of the tracks in the tracker

  /// called by Map, to test if a hit combination is eligible
  virtual bool TestCombination(TrackType type); ///< \param type: track type
  /// incompatibility check betweeen newtrk and oldtrk
  virtual bool Compare(ETFVTrack *newtrk, ETFVTrack *oldtrk, TrackType type);
  /// the same as the TrackType version, but using track array c instead of type
  /// just for serving CleanUp() method
  virtual int Compare(ETFVTrack *newtrk, ETFVTrack *oldtrk);
  // 3D tracking toolkit //
  /// clean eliminated tracks and filter incompatible ones
  virtual void CleanUp(TrackType type, int n3Dtrk);
  /// to tell if (X,U,V) combination is from the same 3D track
  /// if so, return l: y=k2*z+b2 and the inconsistency xMiss3D[3] in the 3 DC central planes
  virtual bool Compatible(ETFVTrack *x, ETFVTrack *u, ETFVTrack *v,
    double &k2, double &b2, double *xMiss3D);
  // the same as the one taking ETFVTrack parameters
  virtual bool Compatible(double kx, double bx, double ku, double bu,
    double kv, double bv, double &k2, double &b2, double *xMiss3D);
  /// \retval false: if obtained drift time out of range
  virtual bool SetDriftDistance(ETFVTrack *trk);

  ETFTOFWall *fTOFWall; // the TOFWall associated with the DC array
  double fPhiAvrg; ///< the average of phi-s of the 3 DCs
};

#endif
